package com.wlyy.bcwlw.sys.operationlog.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wlyy.bcwlw.base.BaseController;
import com.wlyy.bcwlw.sys.operationlog.dao.UserOperationLogDAO;
import com.wlyy.bcwlw.sys.operationlog.entity.UserOperationLogDTO;
import com.wlyy.bcwlw.sys.operationlog.service.UserOperationLogService;

@Controller
@RequestMapping("/sys/log")
public class SysUserOperationLogController extends BaseController {

	@Autowired
	private UserOperationLogService userOperationLogService;
	@Autowired
	private UserOperationLogDAO userOperationLogDAO;
	
	@RequestMapping("/index")
	public String typeListView(HttpServletRequest request, HttpServletResponse response) throws Exception{
		return "sys/log/log-index";
	}
	
	@RequestMapping("/list")
	public String logList(HttpServletRequest request, HttpServletResponse response) throws Exception{
		int curPage = getPageNum(request);
		int limit = getInternal(request);
		String sortName = getSortName(request);
		String sortOrder = getSortOrder(request);
		
		String queryName = get(request,"queryName");
		String beginTime = get(request,"beginTime");
		String endTime =  get(request,"endTime");
		
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		if(StringUtils.isNotEmpty(queryName)){
			paramMap.put("queryName", queryName);
		}
		if(StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(endTime)){
			paramMap.put("beginTime", beginTime);
			paramMap.put("endTime", endTime);
		}
		if(StringUtils.isNotEmpty(sortName) && StringUtils.isNotEmpty(sortOrder)){
			paramMap.put("orderby", sortName+" "+sortOrder);
		}
		
		int records  = userOperationLogDAO.queryCountLogsByCriteria(paramMap);
		List<UserOperationLogDTO> list = userOperationLogDAO.queryLogsByCriteria(paramMap, getRecordStart(records, curPage, limit), limit);
		
		
		processJsonData4Grid(request, response, limit, curPage, records, list);
		
		return null;
	}
}
